package com.pwt.controller.watch;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.entity.ProductStatistics;
import com.pwt.entity.WhatResult;
import com.pwt.model.WhatResultModel;
import com.pwt.model.WhatResultVoModel;
import com.pwt.service.WhatResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/4
 */
@RestController
@Tag(name = "全局监控指标",description = "全局监控指标")
public class WhatResultController {

    private WhatResultService whatResultService;

    public WhatResultController(WhatResultService whatResultService) {
        this.whatResultService = whatResultService;
    }

    @GetMapping("/what-results-global")
    @Operation(description = "获取Global overviews 全局监控指标列表",summary = "获取 Global overviews 全局监控指标列表")
    public List<WhatResult> getGlobalList(){
       return this.whatResultService.getGlobalList();
    }

    @GetMapping("/what-results-user")
    @Operation(description = "获取 User overviews 监控指标列表",summary = "获取User overviews 监控指标列表")
    public List<WhatResult> getUserList(){
        return this.whatResultService.getUserList();
    }

    @GetMapping("/what-results")
    @Operation(description = "获取监控指标列表",summary = "获取监控指标列表")
    public List<WhatResult> getList(){
        return this.whatResultService.getList();
    }

    @PostMapping("/what-result")
    @Operation(description = "新增监控指标对象",summary = "新增监控指标对象")
    //@PreAuthorize("hasAnyAuthority('watch::global::add','watch::user::add')")
    public WhatResult add(@RequestBody WhatResultModel whatResultModel) throws CustomException {
        return this.whatResultService.add(whatResultModel);
    }

    @GetMapping("/what-results/{id}")
    @Operation(description = "根据监控id查询选取列表",summary = "根据监控id查询选取列表")
    WhatResultVoModel getWhatResultById(@PathVariable(required = true) String id) throws CustomException {
        return this.whatResultService.getWhatResultById(id);
    }

    @PutMapping("/what-result")
    @Operation(description = "修改监控指标对象",summary = "修改监控指标对象")
    //@PreAuthorize("hasAnyAuthority('watch::global::edit','watch::user::edit')")
    public WhatResult update(@RequestBody @Validated(value = Update.class) WhatResultModel whatResultModel) throws CustomException {
        return this.whatResultService.update(whatResultModel);
    }

    @PostMapping("/what-result/copy/{id}")
    @Operation(description = "复制监控指标对象根据id",summary = "复制监控指标对象根据id")
    //@PreAuthorize("hasAnyAuthority('watch::global::copy','watch::user::copy')")
    public void  copy(@Parameter(name = "id", description = "监控指标对象id")  @PathVariable(required = true) String id) throws CustomException {
        this.whatResultService.copyWhatResult(id);
    }

    @DeleteMapping("/what-result/{id}")
    @Operation(description = "删除监控指标对象根据id",summary = "删除监控指标对象根据id")
    //@PreAuthorize("hasAnyAuthority('watch::global::delete','watch::user::delete')")
    public void  delete(@Parameter(name = "id", description = "监控指标对象id")  @PathVariable(required = true) String id) throws CustomException {
        this.whatResultService.delete(id);
    }

}
